package com.dog.framework.log.event;


import com.dog.framework.core.utils.BeanCopyUtils;
import com.dog.modules.system.api.dto.request.SysOperLogAddReqDto;
import com.dog.modules.system.api.feign.SysOperLogFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 异步调用日志服务
 *
 * @author liuxk
 */
@Service
public class LogEventListener {

    @Autowired
    private SysOperLogFeignClient sysOperLogFeignClient;

    /**
     * 保存系统日志记录
     */
    @Async
    @EventListener
    public void saveLog(OperLogEvent operLogEvent) {
        SysOperLogAddReqDto sysOperLog = BeanCopyUtils.copy(operLogEvent, SysOperLogAddReqDto.class);
        sysOperLogFeignClient.add(sysOperLog);
    }

}
